home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / tvmouse.exe / TVEDIT1.CPP < prev    next >
C/C++ Source or Header  |  1992-06-10  |  4KB  |  163 lines

  1. /*----------------------------------------------------------*/
  2. /*                                                          */
  3. /*   Turbo Vision 1.0                                       */
  4. /*   Copyright (c) 1991 by Borland International            */
  5. /*                                                          */
  6. /*   Turbo Vision TVEDIT source file                        */
  7. /*----------------------------------------------------------*/
  8.  
  9. #define Uses_TApplication
  10. #define Uses_TEditWindow
  11. #define Uses_TDeskTop
  12. #define Uses_TRect
  13. #define Uses_TEditor
  14. #define Uses_TFileEditor
  15. #define Uses_TFileDialog
  16. #define Uses_TChDirDialog
  17.  
  18. #include <tv.h>
  19.  
  20. #include "tvedit.h"
  21.  
  22. #include <stdlib.h>
  23. #include <stdarg.h>
  24. #include <strstrea.h>
  25. #include <iomanip.h>
  26.  
  27. TEditWindow *clipWindow;
  28.  
  29. TEditWindow *TEditorApp::openEditor( const char *fileName, Boolean visible )
  30. {
  31.     TRect r = deskTop->getExtent();
  32.     TView *p = validView( new TEditWindow( r, fileName, wnNoNumber ) );
  33.     if( !visible )
  34.         p->hide();
  35.     deskTop->insert( p );
  36.     return (TEditWindow *)p;
  37. }
  38.  
  39. TEditorApp::TEditorApp() :
  40.     TProgInit( TEditorApp::initStatusLine,
  41.                TEditorApp::initMenuBar,
  42.                TEditorApp::initDeskTop
  43.              ),
  44.     TApplication()
  45. {
  46.  
  47.     TCommandSet ts;
  48.     ts.enableCmd( cmSave );
  49.     ts.enableCmd( cmSaveAs );
  50.     ts.enableCmd( cmCut );
  51.     ts.enableCmd( cmCopy );
  52.     ts.enableCmd( cmPaste );
  53.     ts.enableCmd( cmClear );
  54.     ts.enableCmd( cmUndo );
  55.     ts.enableCmd( cmFind );
  56.     ts.enableCmd( cmReplace );
  57.     ts.enableCmd( cmSearchAgain );
  58.     disableCommands( ts );
  59.  
  60.     TEditor::editorDialog = doEditDialog;
  61.     clipWindow = openEditor( 0, False );
  62.     if( clipWindow != 0 )
  63.         {
  64.         TEditor::clipboard = clipWindow->editor;
  65.         TEditor::clipboard->canUndo = False;
  66.         }
  67. }
  68.  
  69. void TEditorApp::fileOpen()
  70. {
  71.     char fileName[MAXPATH];
  72.     strcpy( fileName, "*.*" );
  73.  
  74.     if( execDialog( new TFileDialog( "*.*", "Open file",
  75.             "~N~ame", fdOpenButton, 100 ), fileName) != cmCancel )
  76.         openEditor( fileName, True );
  77. }
  78.  
  79. void TEditorApp::fileNew()
  80. {
  81.     openEditor( 0, True );
  82. }
  83.  
  84. void TEditorApp::changeDir()
  85. {
  86.     execDialog( new TChDirDialog( cdNormal, 0 ), 0 );
  87. }
  88.  
  89. void TEditorApp::dosShell()
  90. {
  91.     suspend();
  92.     system("cls");
  93.     cout << "Type EXIT to return...";
  94.     system( getenv( "COMSPEC"));
  95.     resume();
  96.     redraw();
  97. }
  98.  
  99. void TEditorApp::showClip()
  100. {
  101.     clipWindow->select();
  102.     clipWindow->show();
  103. }
  104.  
  105. void TEditorApp::tile()
  106. {
  107.     deskTop->tile( deskTop->getExtent() );
  108. }
  109.  
  110. void TEditorApp::cascade()
  111. {
  112.     deskTop->cascade( deskTop->getExtent() );
  113. }
  114.  
  115. void TEditorApp::handleEvent( TEvent& event )
  116. {
  117.     TApplication::handleEvent( event );
  118.     if( event.what != evCommand )
  119.         return;
  120.     else
  121.         switch( event.message.command )
  122.             {
  123.             case cmOpen:
  124.                 fileOpen();
  125.                 break;
  126.  
  127.             case cmNew:
  128.                 fileNew();
  129.                 break;
  130.  
  131.             case cmChangeDrct:
  132.                 changeDir();
  133.                 break;
  134.  
  135.             case cmDosShell:
  136.                 dosShell();
  137.                 break;
  138.  
  139.             case cmShowClip:
  140.                 showClip();
  141.                 break;
  142.  
  143.             case cmTile:
  144.                 tile();
  145.                 break;
  146.  
  147.             case cmCascade:
  148.                 cascade();
  149.                 break;
  150.  
  151.             default:
  152.                 return ;
  153.             }
  154.     clearEvent( event );
  155. }
  156. int main()
  157. {
  158.     TEditorApp editorApp;
  159.     editorApp.run();
  160.     return 0;
  161. }
  162.  
  163.